-------------------------------------------------------------
--					Add Procedure
-------------------------------------------------------------
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

IF EXISTS(SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Sales_SaveSales]') AND type in (N'P', N'PC'))
BEGIN
DROP PROCEDURE [Sales_SaveSales]
END
GO

Create Procedure [dbo].[Sales_SaveSales]
(
	@SalesID int,
	@ProductID int,
	@SalesDescription nvarchar(max),
	@SalesDate DateTime,
	@SalesNumber int,
	@TotalSales float,
	@UnitPrice float
)
AS
	if exists(select * from Sales WITH(NOLOCK) where SalesID = @SalesID and ProductID = @ProductID)
		update Sales set
		SalesDescription=@SalesDescription,
		SalesDate=@SalesDate,
		SalesNumber=@SalesNumber,
		TotalSales=@TotalSales,
		UnitPrice=@UnitPrice,
		SalesUpdateDate=GETDATE()
		where SalesID = @SalesID and ProductID = @ProductID;
	else
		insert into Sales
		(
			ProductID,
			SalesDescription,
			SalesDate,
			SalesNumber,
			TotalSales,
			UnitPrice,
			IsDeleted,
			SalesUpdateDate
		) 
		values
		(
			@ProductID,
			@SalesDescription,
			@SalesDate,
			@SalesNumber,
			@TotalSales,
			@UnitPrice,
			0,
			GETDATE() 
		)
	